{$CLEO .cs}
{$USE CLEO+}
nop
script_name 'STCARHP'
wait 0
wait 0

if
    0AA2: 31@ = load_dynamic_library "CLEO+.cleo"
jf @ILoveMyGirlfriendJessica
if
    0AA4: 30@ = get_dynamic_library_procedure "GetCleoPlusVersion" library 31@
then
    0AA7: call_function_return 30@ num_params 0 pop 0 29@
end
0AA3: free_dynamic_library 31@
if
    29@ >= 0x1020000
jf @ILoveMyGirlfriendJessica


int iCar
float fSpeed, fThreshold 


:Main
wait 500

:ResetTimer
TIMERA = 0
fThreshold = 1.0

while true
    wait 0
    if
        is_player_playing $PLAYER_CHAR
    jf @Main
    if
        is_char_sitting_in_any_car $PLAYER_ACTOR
    jf @Main
    if and
        not is_char_in_flying_vehicle $PLAYER_ACTOR
        not is_char_in_any_boat $PLAYER_ACTOR
        not is_char_in_any_train $PLAYER_ACTOR
        not is_player_in_remote_mode $PLAYER_CHAR
        is_player_control_on $PLAYER_CHAR
    jf @Main  
    if
        is_button_pressed 0 16
    jf @ResetTimer        
    if and
        not is_button_pressed 0 6
        not is_button_pressed 0 14
    jf @ResetTimer
    store_car_char_is_in_no_save iCar $PLAYER_ACTOR
    if and
        not is_car_in_water iCar        
        not is_car_upsidedown iCar
    jf @ResetTimer
    if
        not is_vehicle_on_all_wheels iCar    
    then
        TIMERB = 0
    else
        if
            TIMERB < 500
        jf @ResetTimer
    end 
    get_car_speed fSpeed car iCar
    if
        fSpeed < fThreshold
    jf @ResetTimer
    if
        TIMERA > 1000
    jf continue
    cset_lvar_float_to_lvar_int fSpeed = TIMERA
    fSpeed *= 0.0004
    fSpeed += 0.8
    clamp_float fSpeed min 1.0 max 4.0 store_to fSpeed
    set_car_forward_speed iCar fSpeed
    fThreshold = fSpeed
    fThreshold += 1.0    
end



        
:ILoveMyGirlfriendJessica
TIMERA = 0

repeat
    0AD1: print_formatted_now "Stucked Cars Helper: CLEO+ 1.2.0 or newer required. Please download and install it in cleo folder." time 100
    wait 0
    if or
        89E7: not is_player_control_on $PLAYER_CHAR
        016B: fading
    then
        TIMERA = 0
    end
until TIMERA > 8000

terminate_this_custom_script